package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.housekeepingServUser.IDeleteHousekeepingServUserBMO;
import com.java110.mall.cart.bmo.housekeepingServUser.IGetHousekeepingServUserBMO;
import com.java110.mall.cart.bmo.housekeepingServUser.ISaveHousekeepingServUserBMO;
import com.java110.mall.cart.bmo.housekeepingServUser.IUpdateHousekeepingServUserBMO;
import com.java110.dto.housekeeping.HousekeepingServUserDto;
import com.java110.po.housekeeping.HousekeepingServUserPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/housekeepingServUser")
public class HousekeepingServUserApi {

    @Autowired
    private ISaveHousekeepingServUserBMO saveHousekeepingServUserBMOImpl;
    @Autowired
    private IUpdateHousekeepingServUserBMO updateHousekeepingServUserBMOImpl;
    @Autowired
    private IDeleteHousekeepingServUserBMO deleteHousekeepingServUserBMOImpl;

    @Autowired
    private IGetHousekeepingServUserBMO getHousekeepingServUserBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServUser/saveHousekeepingServUser
     * @path /app/housekeepingServUser/saveHousekeepingServUser
     */
    @RequestMapping(value = "/saveHousekeepingServUser", method = RequestMethod.POST)
    public ResponseEntity<String> saveHousekeepingServUser(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "servId", "请求报文中未包含servId");
        Assert.hasKeyAndValue(reqJson, "staffId", "请求报文中未包含staffId");
        Assert.hasKeyAndValue(reqJson, "staffName", "请求报文中未包含staffName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含state");


        HousekeepingServUserPo housekeepingServUserPo = BeanConvertUtil.covertBean(reqJson, HousekeepingServUserPo.class);
        return saveHousekeepingServUserBMOImpl.save(housekeepingServUserPo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServUser/updateHousekeepingServUser
     * @path /app/housekeepingServUser/updateHousekeepingServUser
     */
    @RequestMapping(value = "/updateHousekeepingServUser", method = RequestMethod.POST)
    public ResponseEntity<String> updateHousekeepingServUser(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "servId", "请求报文中未包含servId");
        Assert.hasKeyAndValue(reqJson, "staffId", "请求报文中未包含staffId");
        Assert.hasKeyAndValue(reqJson, "staffName", "请求报文中未包含staffName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含state");
        Assert.hasKeyAndValue(reqJson, "remark", "请求报文中未包含remark");
        Assert.hasKeyAndValue(reqJson, "servUserId", "servUserId不能为空");


        HousekeepingServUserPo housekeepingServUserPo = BeanConvertUtil.covertBean(reqJson, HousekeepingServUserPo.class);
        return updateHousekeepingServUserBMOImpl.update(housekeepingServUserPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServUser/deleteHousekeepingServUser
     * @path /app/housekeepingServUser/deleteHousekeepingServUser
     */
    @RequestMapping(value = "/deleteHousekeepingServUser", method = RequestMethod.POST)
    public ResponseEntity<String> deleteHousekeepingServUser(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "shopId");

        Assert.hasKeyAndValue(reqJson, "servUserId", "servUserId不能为空");


        HousekeepingServUserPo housekeepingServUserPo = BeanConvertUtil.covertBean(reqJson, HousekeepingServUserPo.class);
        return deleteHousekeepingServUserBMOImpl.delete(housekeepingServUserPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 小区ID
     * @return
     * @serviceCode /housekeepingServUser/queryHousekeepingServUser
     * @path /app/housekeepingServUser/queryHousekeepingServUser
     */
    @RequestMapping(value = "/queryHousekeepingServUser", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingServUser(@RequestParam(value = "shopId") String shopId,
                                                            @RequestParam(value = "servId", required = false) String servId,
                                                            @RequestParam(value = "page") int page,
                                                            @RequestParam(value = "row") int row) {
        HousekeepingServUserDto housekeepingServUserDto = new HousekeepingServUserDto();
        housekeepingServUserDto.setPage(page);
        housekeepingServUserDto.setRow(row);
        housekeepingServUserDto.setShopId(shopId);
        housekeepingServUserDto.setServId(servId);
        return getHousekeepingServUserBMOImpl.get(housekeepingServUserDto);
    }
}
